package sdk.webview.fmc.com.fmcsdk.check.activity;

import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.MediaController;
import android.widget.RelativeLayout;
import android.widget.VideoView;

import sdk.webview.fmc.com.fmcsdk.R;
import sdk.webview.fmc.com.fmcsdk.util.Constant;
import sdk.webview.fmc.com.fmcsdk.view.FMCProgressDialog;

public class VideoPlaybackActivity extends AppCompatActivity {
    private VideoView video_view;
    private RelativeLayout rl_close;
    @Override
    protected void onCreate(@Nullable @androidx.annotation.Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_playback);

         FMCProgressDialog loadingDialog = new FMCProgressDialog(this);

        video_view = findViewById(R.id.video_view);
        rl_close = findViewById(R.id.rl_close);

        String url = getIntent().getStringExtra("videoUrl");
        Uri uri = Uri.parse(url);
        video_view.setVideoURI(uri);
        MediaController mediaController = new MediaController(this);
        video_view.setMediaController(mediaController);
        mediaController.setAnchorView(video_view);
        video_view.requestFocus();
        loadingDialog.show();
        video_view.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                loadingDialog.dismiss();
                video_view.start();
            }
        });


        rl_close.setOnClickListener(v ->{
            finish();
        });

        // 设置弹窗的大小和样式
        Window window = getWindow();
        if (window != null) {
            window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
            window.setBackgroundDrawableResource(android.R.color.transparent);  // 使背景透明
        }
    }
}
